package com.example.wzh.rxdemo.rx;

import com.example.wzh.rxdemo.LogTag;
import com.wzh.advancelog.log.WzhLog;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.Disposable;

public class MyObserver<T> implements Observer<T> {
        private final CompositeDisposable compositeDisposable;

        public MyObserver(CompositeDisposable compositeDisposable) {
            this.compositeDisposable = compositeDisposable;
        }

        @Override
        public void onSubscribe(@NonNull Disposable d) {
            if (compositeDisposable != null) {
                compositeDisposable.add(d);
            }
            WzhLog.i(LogTag.TAG_WZH, "onSubscribe");
        }

        @Override
        public void onNext(@NonNull T t) {
            WzhLog.i(LogTag.TAG_WZH, "event data:" + t);

        }

        @Override
        public void onError(@NonNull Throwable e) {
            WzhLog.e(LogTag.TAG_WZH, e.getMessage());
        }

        @Override
        public void onComplete() {
            WzhLog.i(LogTag.TAG_WZH, "onComplete");
        }
    }
